Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deployment: Dockerfile and Smithery config #3

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

calclavia
Copy link

@calclavia calclavia commented Jan 23, 2025

This pull request introduces the following updates:

  • Dockerfile: Introduces a Dockerfile to package the MCP for deployment across various environments.
  • Smithery Configuration: Adds a Smithery YAML file, which specifies how to start the MCP and the configuration options it supports. It allows you to deploy your MCP to Smithery, serving it over SSE so end-users do not need to install additional dependencies. To deploy, merge this PR, then visit your server page and click "Deploy" under the deployments page.
  • README: Updates the README to include installation instructions via Smithery and a popularity badge. Note that the installation only works after the server is deployed on Smithery.

Please review these updates to verify their accuracy for your server and feel free to customize it to your needs. Let me know if you have any questions. 🙂

Summary by CodeRabbit

  • New Features

    • Added Smithery badge to project README
    • Introduced new installation method via Smithery
    • Created Smithery configuration for MCP startup
  • Chores

    • Optimized Docker build process with multi-stage build
    • Improved project documentation and installation instructions

Copy link

coderabbitai bot commented Jan 23, 2025

Walkthrough

This pull request introduces a multi-stage Dockerfile for a Node.js TypeScript application, adds a Smithery badge and installation method to the README, and creates a new Smithery configuration file. The changes optimize the Docker build process, enhance project documentation, and provide a new installation method through the Smithery platform. The modifications aim to improve the project's build efficiency, visibility, and ease of installation.

Changes

File Changes
Dockerfile Implemented multi-stage build process for Node.js TypeScript application:
- First stage (builder) sets up dependency installation and TypeScript build
- Second stage (release) creates a minimal production image
README.md - Added Smithery badge
- Introduced new "Installing via Smithery" section
- Added installation command for NPX Fetch via Smithery
smithery.yaml - Created new Smithery configuration file
- Added startCommand with stdio configuration
- Defined configSchema using JSON Schema
- Implemented commandFunction for MCP startup

Sequence Diagram

sequenceDiagram
    participant D as Dockerfile
    participant B as Build Stage
    participant R as Release Stage
    participant A as Application

    D->>B: Copy source code
    B->>B: Install dependencies
    B->>B: Compile TypeScript
    B-->>R: Copy compiled dist
    R->>R: Install production dependencies
    R->>A: Start application
Loading

Poem

🐰 A Dockerfile so lean and bright,
Smithery's badge now shining light,
Builds that dance with alpine grace,
NPX Fetch finds its new space,
Coding magic takes its flight! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
smithery.yaml (2)

8-11: Add error handling to command function.

The command function should handle potential configuration errors and validate inputs.

  commandFunction:
    |-
-   config => ({command: 'node', args: ['dist/index.js']})
+   config => {
+     // Validate config
+     if (config && typeof config !== 'object') {
+       throw new Error('Invalid configuration provided');
+     }
+     return {
+       command: 'node',
+       args: ['dist/index.js', ...buildArgs(config)]
+     };
+   }
🧰 Tools
🪛 yamllint (1.35.1)

[error] 11-11: no new line character at the end of file

(new-line-at-end-of-file)


11-11: Add newline at end of file.

Add a newline character at the end of the file to comply with POSIX standards.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 11-11: no new line character at the end of file

(new-line-at-end-of-file)

README.md (1)

36-42: Enhance Smithery installation documentation.

The current documentation needs improvement:

  1. Add prerequisites for using Smithery
  2. Explain what Smithery is and its benefits
  3. Document security implications of using -y flag

Consider adding:

### Prerequisites
- Node.js 18 or higher
- NPM 7 or higher
- Claude Desktop installed

### Installing via Smithery

[Smithery](https://smithery.ai) is a deployment platform that enables seamless integration of MCPs with Claude Desktop. It handles dependency management and updates automatically.

To install NPX Fetch via Smithery:

```bash
# Interactive installation (recommended)
npx @smithery/cli install @tokenizin/mcp-npx-fetch --client claude

# Non-interactive installation (skips prompts)
npx -y @smithery/cli install @tokenizin/mcp-npx-fetch --client claude

Note: The -y flag skips installation prompts. Only use it if you trust the package and understand the security implications.


</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between c0499be179b1bfa641c8478fdfae6ac43483470b and 22707c2f863bae3f9c0bd152c454df03399d6c61.

</details>

<details>
<summary>📒 Files selected for processing (3)</summary>

* `Dockerfile` (1 hunks)
* `README.md` (2 hunks)
* `smithery.yaml` (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 yamllint (1.35.1)</summary>

<details>
<summary>smithery.yaml</summary>

[error] 11-11: no new line character at the end of file

(new-line-at-end-of-file)

</details>

</details>

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Comment on lines +5 to +7
configSchema:
# JSON Schema defining the configuration options for the MCP.
type: object
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance config schema with required properties and validation.

The current schema is too basic. Consider adding:

  • Required properties for configuration
  • Property types and validation rules
  • Environment variable validation

Example schema:

  configSchema:
    type: object
+   required: []
+   properties:
+     port:
+       type: number
+       description: "Port to run the server on"
+       default: 3000
+     logLevel:
+       type: string
+       enum: ["debug", "info", "warn", "error"]
+       default: "info"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
configSchema:
# JSON Schema defining the configuration options for the MCP.
type: object
configSchema:
# JSON Schema defining the configuration options for the MCP.
type: object
required: []
properties:
port:
type: number
description: "Port to run the server on"
default: 3000
logLevel:
type: string
enum: ["debug", "info", "warn", "error"]
default: "info"

Comment on lines +1 to +34
# Generated by https://smithery.ai. See: https://smithery.ai/docs/config#dockerfile
# Use a Node.js image with a specific version that supports TypeScript
FROM node:18-alpine AS builder

# Create app directory
WORKDIR /usr/src/app

# Copy package.json and package-lock.json for dependency installation
COPY package.json package-lock.json ./

# Install the dependencies
RUN npm install

# Copy the rest of the application code
COPY . .

# Build the TypeScript code
RUN npm run build

# Use a smaller Node.js image to reduce the size of the final image
FROM node:18-alpine AS release

# Create app directory
WORKDIR /usr/src/app

# Copy the compiled code from the builder stage
COPY --from=builder /usr/src/app/dist ./dist
COPY package.json ./

# Install only production dependencies
RUN npm install --production

# Specify the command to run the MCP server
ENTRYPOINT ["node", "dist/index.js"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add security and best practices to Dockerfile.

Consider the following improvements:

  1. Create a non-root user for security
  2. Add health check
  3. Clean npm cache
  4. Add .dockerignore
 FROM node:18-alpine AS builder
+# Add non-root user
+RUN addgroup -S appgroup && adduser -S appuser -G appgroup
 
 WORKDIR /usr/src/app
+USER appuser
 
 COPY package.json package-lock.json ./
 
-RUN npm install
+RUN npm ci && npm cache clean --force
 
 COPY . .
 
 RUN npm run build
 
 FROM node:18-alpine AS release
+# Add non-root user
+RUN addgroup -S appgroup && adduser -S appuser -G appgroup
 
 WORKDIR /usr/src/app
+USER appuser
 
 COPY --from=builder /usr/src/app/dist ./dist
 COPY package.json ./
 
-RUN npm install --production
+RUN npm ci --only=production && npm cache clean --force
 
+# Add health check
+HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
+  CMD node -e "require('http').get('http://localhost:${PORT}/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1))"
+
 ENTRYPOINT ["node", "dist/index.js"]

Also create a .dockerignore file:

node_modules
npm-debug.log
Dockerfile
.dockerignore
.git
.gitignore
README.md

Committable suggestion skipped: line range outside the PR's diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant